//2009/10/25 18:06:53
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class PrintScheduler
{
public:
    string getOutput(vector <string> threads, vector <string> slices)
    {
        string ret = "";
        vector<int> idx(threads.size(), 0);
        for (int i=0; i<slices.size(); i++)
        {
			stringstream s(slices[i]);
			int thread;
			int unit;
			s >> thread >> unit;
			for(int j=0; j<unit; j++)
			{
				ret += threads[thread][idx[thread]];
				idx[thread] = (idx[thread] + 1) % threads[thread].size();
			}
        }
		return ret;
    }
};
